#define _CRT_SECURE_NO_WARNINGS	

#include<stdio.h>

int leap_year(int n);
int sum_day(int n, int x);
int month1(int x, int y);
int main()
{
    int year, month;
    scanf("%d %d", &year, &month);
    printf("%d-%d\n", year, month);
    printf(" Sun Mon Tue Wed Thu Fri Sat\n");
    for (int j = 0; j < (sum_day(year, month) % 7 + 1) % 7; j++)
    {
        printf("    ");
    }
    int count = sum_day(year, month) % 7 + 1;
    for (int i = 1; i <= Month(month, year); i++)
    {
        printf("%4d", i);
        count++;
        if (count % 7 == 0)
        {
            printf("\n");
        }
    }
    return 0;
}

int leap_year(int n)
{
    if ((n % 4 == 0 && n % 100 != 0) || (n % 400 == 0))
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int sum_day(int n, int x)
{
    int sum = 0;
    for (int i = 1; i < n; i++)
    {
        if (leap_year(i))
        {
            sum = sum + 366;
        }
        else
        {
            sum = sum + 365;
        }
    }
    switch (x - 1)
    {
    case 12:
        sum = sum + 31;
    case 11:
        sum = sum + 30;
    case 10:
        sum = sum + 31;
    case 9:
        sum = sum + 30;
    case 8:
        sum = sum + 31;
    case 7:
        sum = sum + 31;
    case 6:
        sum = sum + 30;
    case 5:
        sum = sum + 31;
    case 4:
        sum = sum + 30;
    case 3:
        sum = sum + 31;
    case 2:
        sum = sum + ((leap_year(n)) ? 29 : 28);
    case 1:
        sum = sum + 31;
        break;
    }
    return sum;
}

int Month(int x, int y)
{
    switch (x)
    {
    case 12:
        return 31;
    case 11:
        return 30;
    case 10:
        return 31;
    case 9:
        return 30;
    case 8:
        return 31;
    case 7:
        return 31;
    case 6:
        return 30;
    case 5:
        return 31;
    case 4:
        return 30;
    case 3:
        return 31;
    case 2:
        return (leap_year(y)) ? 29 : 28;
    case 1:
        return 31;
    }
}